package com.pandas.community.entity;

/**
 * 封装页面相关信息
 */
public class Page {
    //当前页
    private int currentPage = 1;
    //页面可容纳的info数量
    private int pageCapacity = 10;
    //页面地址
    private String path;
    //页面数据总量
    private int infoAmount;



    public int getCurrentPage() {
        return currentPage;
    }

    public void setCurrentPage(int currentPage) {
        if(currentPage >= 1){
            this.currentPage = currentPage;
        }
    }

    public int getPageCapacity() {
        return pageCapacity;
    }

    public void setPageCapacity(int pageCapacity) {
        //自定义设置页面评论数1~100
        if(pageCapacity >= 1 && pageCapacity <= 100){
            this.pageCapacity = pageCapacity;
        }
    }

    public String getPath() {
        return path;
    }

    public void setPath(String path) {
        this.path = path;
    }

    public int getInfoAmount() {
        return infoAmount;
    }

    public void setInfoAmount(int infoAmount) {
        this.infoAmount = infoAmount;
    }

    //当前页面的起始信息数
    public int getOffset(){
        //currentPage*pageCapacity - pageCapacity
        return (currentPage-1) * pageCapacity;
    }

    //总页数
    public int getPagesAmount(){
        if(infoAmount % pageCapacity == 0){
            return infoAmount / pageCapacity;
        }else{
            return infoAmount / pageCapacity +1;
        }
    }

    //显示的第一个页面
    public int getStartPage(){
        //自定义设置前三页
        int startPage = currentPage - 3;
        return startPage < 1 ? 1 : startPage;
    }

    //显示的最后一个页面
    public int getEndPage(){
        //自定义设置后三页
        int endPage = currentPage + 3;
        int total = getPagesAmount();
        return endPage > total ? total : endPage;
    }
}
